package com.skyolder.milkbee.repository;

import com.skyolder.milkbee.domain.Leaguer;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;

import java.util.List;

/**
 * Spring Data JPA repository for the Leaguer entity.
 */
@SuppressWarnings("unused")
public interface LeaguerRepository extends JpaRepository<Leaguer,Long> {
	Leaguer findByUserId(Long userId);
	@Query("from Leaguer as le where le.userId in (select fl.toUserId from Follow as fl where fl.fromUserId=?1)")
	Page<Leaguer> doQueryFocus(Long userId, Pageable pageable);
	
	@Query("from Leaguer as le where le.userId in (select fl.fromUserId from Follow as fl where fl.toUserId=?1)")
	Page<Leaguer> doQueryFans(Long userId, Pageable pageable);
	
	
	@Query("select new com.skyolder.milkbee.dto.StrangerLeaguer(st.id,le.id,le.userId,st.categoryId,le.name,le.nikename,le.score,le.gold,le.cardCount,le.commentCount,le.mana,le.estateRank,le.accusation) from Stranger st ,Leaguer as le where st.forbidden=true and st.leaguerId in (?1) and st.leaguerId=le.id")
	Page<Leaguer> doQueryByIds(List<Long> ids, Pageable pageable);
	
	List<Leaguer> findByMonitorTrue();
	
	Leaguer findOneByUserId(Long userId);
	
	@Query("from Leaguer as le where le.authentication=false and le.identification is not null and LENGTH(le.identification)>=10")
	Page<Leaguer> queryApply(Pageable pageable);
	
	@Query("from Leaguer as le where le.authentication=false and (le.identification is null or LENGTH(le.identification)<=0)")
	Page<Leaguer> queryNoReal(Pageable pageable);
	
	@Query("from Leaguer as le where le.authentication=true")
	Page<Leaguer> queryReal(Pageable pageable);
	
	@Query("from Leaguer as le where le.forbidden=true")
	Page<Leaguer> queryForbidden(Pageable pageable);
	
	@Query("from Leaguer as le where le.accusation>0")
	Page<Leaguer> queryReport(Pageable pageable);

}
